﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using System.IO;
using JumbotCms.Common;
namespace JumbotCms.Install
{
    public partial class _step3 : JumbotCms.Common.BasicPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (System.Web.HttpContext.Current.Application["CMS:BasePath"] == null)
                Response.Redirect("index.aspx");
            else
                if (!Page.IsPostBack)
                    new CreateJson().CreateSystemInfo(doh);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string _Email = f("txtEmail");
            string _UserName = f("txtUserName");
            string _UserPass = f("txtUserPass1");
            string _AdminName = f("txtAdminName");
            string _AdminPass = f("txtAdminPass1");
            doh.Reset();
            doh.AddFieldItem("UserName", _UserName);
            doh.AddFieldItem("UserPass", GetHash32(_UserPass));
            doh.AddFieldItem("Sex", 0);
            doh.AddFieldItem("Email", _Email);
            doh.AddFieldItem("Group", 5);
            doh.AddFieldItem("Login", 1);
            doh.AddFieldItem("IsWriter", 0);
            doh.AddFieldItem("AdminId", 1);
            doh.AddFieldItem("AdminName", _AdminName);
            doh.AddFieldItem("AdminPass", GetHash32(_AdminPass));
            doh.AddFieldItem("AdminFolder", "/");
            doh.AddFieldItem("AdminState", 1);
            doh.AddFieldItem("Setting", ",,");
            doh.AddFieldItem("Birthday", "1980-1-1");
            doh.AddFieldItem("IDType", 1);
            doh.AddFieldItem("State", 1);
            doh.Insert("jcms_normal_user");
            ChkUserLogin(_UserName, _UserPass, 0);
            ChkAdminLogin(_AdminName, _AdminPass, 0);
            //将超级管理员写入配置文件
            string strXmlFile = HttpContext.Current.Server.MapPath("~/_data/config/config.config");
            Jumbot.DataOper.XmlControl XmlTool = new Jumbot.DataOper.XmlControl(strXmlFile);
            XmlTool.Update("Root/Founders", "." + _AdminName + ".");
            XmlTool.Save();
            XmlTool.Dispose();

            //循环调用宏标记入库
            strXmlFile = HttpContext.Current.Server.MapPath("~/_data/config/jcms(contentli).config");
            XmlTool = new Jumbot.DataOper.XmlControl(strXmlFile);
            DataTable dt = XmlTool.GetTable("Lis");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    doh.Reset();
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (dt.Columns[j].ColumnName.ToLower() != "id")
                            doh.AddFieldItem(dt.Columns[j].ColumnName.ToLower(), dt.Rows[i][j].ToString());
                    }
                    doh.Insert("jcms_normal_templatecontentli");
                }
            }
            System.Web.HttpContext.Current.Application.Lock();
            System.Web.HttpContext.Current.Application["System:Info"] = null;
            System.Web.HttpContext.Current.Application.UnLock();
            FinalMessage("安装完成，可以删除install目录<br />登录后台:进行更详细的配置", site.Dir + "admin/login.htm", 0);
        }
    }
}
